package com.hantanger.weblog.dao;
import com.hantanger.weblog.model.Setting;
import com.hantanger.weblog.util.DaoHelper;

public class SettingDao {

	public void insert(Setting setting) {
		update(setting);
	}

	public void update(Setting setting) {
		DaoHelper.save(setting);
	}
	
	public Setting getDefaultSetting(){
		Setting setting = getSettingByName("default");
		if(setting == null){
			setting = new Setting();
			setting.setName("default");
			insert(setting);
		}
		return setting;
	}

	public boolean delete(String name) {
		DaoHelper.delete(Setting.class, name);
		return true;
	}

	public Setting getSettingByName(String name) {
		return DaoHelper.get(Setting.class, name);
	}

}
